import {fetchData} from './fetchData';

//----------------------------------------------------------------------------------------------------------------------
// export const FETCH_DATA = 'fetch-data';
export const RECV_DATA = 'recv-data';
export const RECV_TIMEOUT = 'recv-data-timeout';
export const RECV_ERROR = 'recv-data-error';

export function fetchDataZnjs() {
    return dispatch => {
        fetch('http://localhost:3001')
            .then((res)=>res.json())
            .then((json)=>{
                dispatch(receivedData(json))
            })
            .catch((e)=>{
                dispatch(receiveError(e.toString()))
            });
    }
}

export function receivedData(data) {
    return {type: RECV_DATA, data: data}
}

// export function receiveTimeout() {
//     return {type: RECV_TIMEOUT, message: 'timeout'}
// }

export function receiveError(message) {
    return {type: RECV_ERROR, message: message}
}